/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package collision;

import java.awt.Rectangle;

/**
 *
 * @author iRina
 */
public class Collision {
    
    public Collision(){
        
    }
    
    public void collide(Zombie zombie, Pokemon pokemon, int times){
        
       Rectangle r1 = zombie.getBounds();
       Rectangle r2 = pokemon.getBounds();
       
       if(pokemon.isVisible()){     
        if(r1.intersects(r2)){
            colliding(zombie,pokemon, times);
            zombie.setMove(false);
        }    
        }
      else{
           if(r1.intersects(r2)){
            zombie.setMove(true);
        }
        
        }
    }
    
    public void collide(Zombie zombie, Missile missil, int times){
        Rectangle r1 = zombie.getBounds();
        Rectangle r2 = missil.getBounds();
        
        if(r1.intersects(r2)){
            colliding(zombie,missil);
            missil.setVisible(false);
        }
    }
    
    
    public void colliding(Zombie zombie, Pokemon pkm, int times){
        
        if(times % pkm.getMISSILEDELAY() == 0)
            pkm.setHp(pkm.getHp()-zombie.getDmg());
        
        if(pkm.getHp() <= 0){
            pkm.setVisible(false);
            zombie.setMove(true);
        }
    }
    
    public void colliding(Zombie zombie, Missile missil){
        zombie.setHp(zombie.getHp() - missil.getDmg());
        
        if(zombie.getHp() <= 0)
            zombie.setVisible(false);
    }
    
    
}
